import './main.css'
import { createWeiQi, WeiQiMusic } from '../../bin'

var canvasWarp = document.querySelector('#weiqi')

var weiqi = createWeiQi(canvasWarp, {
  boardSize: 600
});

const music = new WeiQiMusic()
music.goSrc = 'video/go.wav'
music.eatSrc = 'video/eat.wav'
weiqi.useMusic(music)


var steps = JSON.parse(localStorage.getItem('steps')) || [];
steps.forEach(step => {
  weiqi.readStep(step.x, step.y, step.type)
})
weiqi.onAfterPut = function(chess) {
  if (chess.type == 'H') {
    changeChessType('B')
  } else {
    changeChessType('H')
  }
  steps.push(chess)
  localStorage.setItem('steps', JSON.stringify(steps))
}

function changeChessType(type) {
  weiqi.chessType = type
  qizi.innerText = type == 'H' ? '请黑棋落子' : '请白棋落子'
}

hei.onclick = () => changeChessType('H')
bai.onclick = () => changeChessType('B')

